package com.aiti.lulian.service.impl;


import com.aiti.base.core.base.service.iml.BaseSerivceImpl;
import com.aiti.base.core.utils.message.Message;
import com.aiti.lulian.entity.MsgInbox;
import com.aiti.lulian.mapper.MsgInboxMapper;
import com.aiti.lulian.service.MsgInboxService;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class MsgInboxServiceImpl extends BaseSerivceImpl<MsgInboxMapper, MsgInbox> implements MsgInboxService {
    @Override
    public Message read(String baseId) {
        LambdaUpdateWrapper<MsgInbox> wrapper = new LambdaUpdateWrapper<>();
        wrapper.set(MsgInbox::getStatus,1).eq(MsgInbox::getBaseId,baseId);
        this.update(wrapper);
        return Message.success();
    }

    @Override
    public Message innerInfo(String userId) {
        LambdaQueryWrapper<MsgInbox> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(MsgInbox::getStatus, 0).eq(MsgInbox::getReceiverId,userId);
        int unreadCount = this.count(wrapper);
        Map map = new HashMap();
        map.put("unreadCount", unreadCount);
        return Message.success(map);
    }
}
